<template>
  <el-dialog v-model="state.forgetPasswordDialog" title="忘记密码" width="400px">
    <el-form class="login-form" :model="forgetData" :label-position="labelPosition" :rules="rules">
      <el-form-item prop="account" label="请输入您的注册账号">
        <el-input v-model="forgetData.account" placeholder="请输入您的注册账号"></el-input>
      </el-form-item>
      <el-form-item prop="email" label="请输入您的个人邮箱">
        <el-input v-model="forgetData.email" placeholder="请输入您的个人邮箱"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="state.forgetPasswordDialog = false">取消</el-button>
        <el-button type="primary" @click="openChangePassword">下一步</el-button>
      </span>
    </template>
  </el-dialog>

  <el-dialog v-model="state.changePasswordDialog" title="修改密码" width="400px">
    <el-form class="login-form" :model="forgetData" :label-position="labelPosition" :rules="rules">
      <el-form-item prop="password" label="请输入您的新密码">
        <el-input v-model="forgetData.password" placeholder="请输入您的新密码"></el-input>
      </el-form-item>
      <el-form-item prop="repassword" label="请再次输入您的新密码">
        <el-input v-model="forgetData.repassword" placeholder="请再次输入您的新密码"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="state.changePasswordDialog = false">取消</el-button>
        <el-button type="primary" @click="openChangePassword">下一步</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup lang='ts'>
import { ref, reactive } from 'vue'
defineOptions({
  name: 'ForgetPassword'
})
const state = reactive({
  forgetPasswordDialog: false,
  changePasswordDialog: false,
})

interface ForgetData {
  account: string;
  email: string;
  password: string;
  repassword: string;
}

const forgetData: ForgetData = reactive({
  account: '',
  email: '',
  password: '',
  repassword: '',
})

const labelPosition = ref('top')

const rules = reactive({
  account: [{ required: true, message: '请输入您的注册账号', trigger: 'blur' }],
  email: [{ required: true, message: '请输入您的注册邮箱', trigger: 'blur' }],
  password: [{ required: true, message: '请输入您的新密码', trigger: 'blur' }],
  repassword: [{ required: true, message: '请再次输入您的新密码', trigger: 'blur' }],
})

const open = () => {
  state.forgetPasswordDialog = true
}

const openChangePassword = () => {
  state.forgetPasswordDialog = false
  state.changePasswordDialog = true
}

defineExpose({
  open
})
</script>